const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const fs = require('fs');
let app = express();
// 使用中间件
app.use(bodyParser.urlencoded({extended:false}));
app.get('/',(req,res)=>{
    //加载视图
    res.sendFile(path.join(__dirname,'./views/index.html'));
})

// 接收post过来的数据
app.post('/addUser',(req,res)=>{
    console.log(req.body);
    if(!fs.existsSync('./data')){
        fs.mkdirSync('./data');
    }
    if(!fs.existsSync('./data/users.json')){
        fs.writeFileSync('./data/users.json',JSON.stringify([]));
    }
})